<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>encodeURIComponent</title>
</head>

<body>
  <div id="test">
    http://www.baidu.com
  </div>
  <br>
  <button id="change">编码</button>
  <button id="recover">复原</button>
  <script>
    const url = 'http://www.baidu.com'
    const res = encodeURIComponent(url);
    const test = document.getElementById('test');
    const change = document.getElementById('change');
    const recover = document.getElementById('recover');
    change.onclick = function () {
      test.innerHTML = res;
    }
    recover.onclick = function () {
      test.innerHTML = url;
    }
  </script>
</body>

</html>